package thread;

public class Bank {
    private int account = 20000;
    public synchronized boolean getMoney(int money)
    {
        int account=getAccount();
        if(account>=money){
            account=account-money;
            Thread.yield();//主动让线程放弃本次剩余时间片
            setAccount(account);
            return true;
        }
         return false;
    }
    public int getAccount(){
        return account;
    }
    public void setAccount(int account){
        this.account=account;
    }
}
